﻿using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using BaseUtils.AppConfig;

namespace BaseUtils
{
    public class BaseService
    {

        public static Root AppConfig;
       // public static string RootPath = ConfigurationManager.AppSettings.Get("RootPath");
        //public static string AppConfigName = RootPath + ConfigurationManager.AppSettings.Get("AppConfig");

        public BaseService(string AppConfigName) { 
            if (AppConfig == null)
            {
                try
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(Root));
                    //Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
                    StreamReader textReader = new StreamReader(AppConfigName, Encoding.UTF8);
                    AppConfig = (Root)xmlSerializer.Deserialize(textReader);
                    //Console.WriteLine($"Camera ID: {AppConfig.Camera.Id }, Time: {AppConfig.Camera.Time}");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
    }
}
